<%@ WebHandler Language="C#" Class="CheckPorts" %>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
using LdExpress;

public class CheckPorts : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        string stVal = "";
        string sqlCommand = "";
        int nSuperAdmin = 0;
        if (context.Session["superadmin"] != null) nSuperAdmin = int.Parse(context.Session["superadmin"].ToString());
        sqlCommand = "Select CostNumber from tbl_customerofferprices  where CostNumber is not Null AND CostNumber <>''";

        sqlCommand += " And UserID in(Select ID from tbl_adminusers where 1=1 AND (IdProvince=" + context.Session["UserProvince"].ToString();
        //" Or FIND_IN_SET('" + context.Session["UserProvince"].ToString() + "',Location))";
        if (context.Session["UserLocation"].ToString().Length > 0)
            sqlCommand += " OR IdProvince in (" + context.Session["UserLocation"].ToString() + ")";
        sqlCommand += "))";
        if (context.Request.QueryString["src"] != null && context.Request.QueryString["src"] == "acc")
        {
            sqlCommand += " AND CostNumber not in (Select FileNumber From tbl_cost_accounting)";
            //WHERE IdProvince=" + context.Session["UserProvince"].ToString() + ")";
        }
        DataSet ds = DBModule.ExecuteQuery(sqlCommand, null, null);

        if (ds.Tables[0].Rows.Count > 0)
        {

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (stVal.Length > 0)
                    stVal += "," + dr["CostNumber"].ToString().Split(',')[0].ToString();
                else
                    stVal = dr["CostNumber"].ToString().Split(',')[0].ToString();
            }

        }
        context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(0));
        context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.Write(stVal);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}